<div class="page-header nav">
  <%= link_to 'Edit', edit_device_path(@device), class: 'btn btn-primary navbar-btn pull-right' %> 
  <h3 class='navbar-text'>
    <%= link_to extface.root_path do %>
      Extface<sup>&hearts;</sup>
    <% end %>
    &raquo;
    <%= link_to t('.devices'), devices_path %>
    &raquo; 
    <%= @device.name %>
  </h3>
</div>
<br />
<% if @job.present? %>
  <div class='alert alert-info job-monitor'>
    See job #<%= @job.id %> execution progress at: <%= link_to job_url(@job), job_path(@job), target: :_blank %>
    <div>
      <div class='text-danger'>You need multi-threaded server to do that!</div>
      <small>(Easiest workaraund: Include <%= link_to 'unicorn-rails', 'https://github.com/samuelkadolph/unicorn-rails', target: :_blank %> in your application)</small>
    </div>
  </div>
<% end %>
<div class='row'>
  <div class='col-sm-6'>
    <dl class="dl-horizontal">
      <dt><%= t('.name') %></dt>
      <dd><%= @device.name %></dd>
      
      <dt><%= t('.parent') %></dt>
      <dd><%= @device.extfaceable.composite_id %></dd>
      
      <dt><%= t('.driver') %></dt>
      <dd><%= @device.driver_name %></dd>
      
      <dt><%= t('.encoding') %></dt>
      <dd><%= @device.encoding %></dd>
    </dl>
  </div>
  <div class='col-sm-6'>
    <dl class="dl-horizontal">
      <dt><%= t('.created') %></dt>
      <dd><%= distance_of_time_in_words_to_now @device.created_at %> ago</dd>
      
      <dt><%= t('.successful_jobs') %></dt>
      <dd>
        <%= @device.jobs.completed.count %>
        <% if @device.jobs.completed.any? %>
          (<%= t('.last') %>: <%= distance_of_time_in_words_to_now @device.jobs.maximum(:completed_at) %> ago)
        <% end %>
      </dd>
      
      <dt><%= t('.failures') %></dt>
      <dd>
        <%= @device.jobs.failed.count %>
        <% if @device.jobs.failed.any? %>
          (<%= t('.last') %>: <%= distance_of_time_in_words_to_now @device.jobs.maximum(:failed_at) %> ago)
        <% end %>
      </dd>
      

    </dl>
  </div>
</div>

<dl class="dl-horizontal">
  <dt><%= t('.client_pull_url') %></dt>
  <dd><pre><%= extface.pull_url(@device.uuid) %></pre></dd>
</dl>

<hr />

<%= driver_control @device.driver %>

<!-- <br />Simulate push data from device

    <div class="input-group">
      <input type="text" id='data' class="form-control">
      <span class="input-group-btn">
        <%= link_to 'Push', extface.push_url(@device.uuid), id: :push, class: 'btn btn-warning'%>
      </span>
    </div>-->

<h1>Jobs</h1>
<table class='table'>
  <thead>
    <tr class='active'>
      <th>Id</th>
      <th>Created</th>
      <th>Description</th>
      <th>Error</th>
      <th>Failed</th>
      <th>Completed</th>
      <th>Connected</th>
    </tr>
  </thead>
 <% @device.jobs.last(10).reverse.each do |job|%>
   <tr>
     <td><%= job.id %></td>
     <td><%= job.created_at %></td>
     <td><%= job.description %></td>
     <td><%= job.error %></td>
     <td><%= job.failed_at %></td>
     <td><%= job.completed_at %></td>
     <td><%= job.connected_at %></td>
   </tr>
 <% end %>
